import UserSession from "@/UserSession";
import { Divider, Radio,Button } from "antd";
import React from "react";
import { Link } from "umi";

class Editing extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      key :"flow",
      radioList:[
        {
          name:"流程配置",
          key:"flow"
        },
        {
          name:"字段配置",
          key:"field"
        },
        {
          name:"数据字典",
          key:"dictionary"
        },
        {
          name:"报表记录",
          key:"report"
        }
      ]
    }
  }

  onChangeRadio = e => {

  }

  doBack = () => {
    const { match: { params: { id } },history } = this.props;
    let rootRouter = UserSession.isSystemKnowledge() ? 'systemKnowledge' : 'myKnowledge'
    history.push({
			pathname: "/knowledgeDesign/"+rootRouter+"/"+id+"/formInteraction/",
			query: {},
		});
  }

  render(){
    const { key,radioList } = this.state;
    const { match: { url, params: { id }, }, location: { pathname, query }, children, route } = this.props;
    console.log(pathname);
    
    let keyValue = radioList.filter((item) => pathname.indexOf(item.key) > -1)?.length > 0 ? radioList.filter((item) => pathname.indexOf(item.key) > -1)[0].key : ''
    return (
      <div style={{padding:15,position:"relative"}}>
        <Radio.Group value={keyValue}>
          {
            radioList.map(item => {
               return (
                <Radio.Button value={item.key} key={item.key}>
                  <Link to={{pathname:pathname.indexOf("systemKnowledge") > -1 ? "/knowledgeDesign/systemKnowledge/" + id + "/formInteraction/edit/" + item.key : "/knowledgeDesign/myKnowledge/" + id + "/formInteraction/edit/" + item.key, query,}}>
                    {item.name}
                  </Link>
                </Radio.Button>
               )
            })
          }
        </Radio.Group>

        <Button type="primary" icon="rollback" ghost onClick={this.doBack} style={{
          position:"absolute",
          right:15,
          top:15
        }}>返回</Button>

        {
          pathname.indexOf("/formInteraction/edit/flow") != -1 ? null : (
            <Divider />
          )
        }
        

        <div>
          {children}
        </div>
      </div>
    )
  }
}

export default Editing